package com.haruhinav.service.impl;

import com.haruhinav.entity.DefaultFace;
import com.haruhinav.entity.extend.DefaultFaceEX;
import com.haruhinav.entity.vo.ResultVO;
import com.haruhinav.mapper.DefaultFaceMapper;
import com.haruhinav.service.DefaultFaceService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DefaultFaceServiceImpl implements DefaultFaceService{

    @Resource
    private DefaultFaceMapper defaultFaceMapper;

    @Override
    public List<DefaultFace> queryDefaultFace() {
        return defaultFaceMapper.queryDefaultFace();
    }

    @Override
    public ResultVO insertDefaultFace(DefaultFace defaultFace) {
        ResultVO result = new ResultVO();
        int count  = defaultFaceMapper.insertDefaultFace(defaultFace);
        if(count > 0 && defaultFace.getId()!=0){
            result.setCode(0);
            result.setMsg("添加成功");
            result.setData(defaultFace);
            return result;
        }
        result.setCode(-1);
        result.setType("error");
        result.setMsg("添加失败");
        return result;
    }

    @Override
    public ResultVO queryDefaultFaceLimit(DefaultFaceEX defaultFaceEX) {
        defaultFaceEX.setPage((defaultFaceEX.getPage()-1) * defaultFaceEX.getPageSize());
        ResultVO result= new ResultVO();
        Map<String ,Object> map = new HashMap<>();
        List<DefaultFace> dflist =defaultFaceMapper.queryDefaultFaceLimit(defaultFaceEX);
        map.put("list",dflist);

        map.put("size",defaultFaceMapper.countDFace());
        result.setData(map);

        return result;
    }

    @Override
    public DefaultFace findDFaceById(int id) {
        return defaultFaceMapper.findDFaceById(id);
    }

    @Override
    public ResultVO updateDFace(String url, int id) {
        ResultVO result = new ResultVO();
        if(defaultFaceMapper.updateDFace(url,id)>0){
            result.setMsg("修改成功");

            return result;
        }
        result.setCode(-1);
        result.setMsg("修改失败");
        result.setType("error");
        return result;
    }

    @Override
    public ResultVO delDFaceById(int id) {
        ResultVO result = new ResultVO();
        if(defaultFaceMapper.delDFaceById(id)>0){
            result.setMsg("删除成功");
            return result;
        }
        result.setCode(-1);
        result.setMsg("删除失败");
        result.setType("error");
        return result;
    }
}
